		Prolog Inference Engine / Help Information
		==========================================

This program illustrates how to handle Prolog-like rules in
PDC Prolog- how to parse them, assert them, and how to build the
inference engine.

Just for fun we have made it behave in ways that are close to the
interpreter defined in the C&M book, however, we have no intention
of representing that it is completely compatible with C&M Prolog.
You should note the following differences:

  - Strings are not lists of integers but instead are a separate type.

  - Floating Point Arithmetic has been implemented

  - Characters have their own type

  - The term reader reads only until an end of line is encountered.

  - Spypoints are not implemented, (trace is).

  - get, get0, tab etc are not implemented, (read, readln, readchar are)

  - we do not support 1.2.3.[] notation for lists, neither are list's
    allowed as arguments to functor and univ

  - can be called with commandline parameters 
	- "pie temp.pro" loads PIE and consults the file "temp.pro"
	- "pie temp.pro start" loads PIE, consults "temp.pro" and calls 
	   start
	- "pie /edit_file("temp.pro")" loads PIE and calls predicate 
	   edit_file

  - tail recursion optimization is implemented for clauses that have a cut 
    ("!") immediately before the tail recursive call.  This tail recursion 
    optimization greatly increases the number of iterations possible for a
    predicate.
    
A list of the implemented standard predicates are:
================================================================================

!				- cut
arg(N,TERM,ARGn)		- unify ARGn with nth argument of TERM
assert(RULE)			- assert
asserta(RULE)			- asserta
assertz(RULE)			- assertz
call(GOAL)			- call
char_int(CHAR,INT)		- conversion between characters and integers
char_real(CHAR,REAL)		- conversion between charactors and reals
clause(HEAD,BODY)		- return clauses from the database
clearwindow			- clears current window
colorsetup(Integer)		- changes color of window (0) or frame (1)
concat(STRING,STRING,STRING)	- concatenation of strings
consult(FILENAME)		- consult a file
consult_str(STRING)		- consults the contents of string
cursor(Row,Col)			- returns curser location or moves curser
cutbacktrack(BTOP)		- dynamic cut to designated backtrack point
date(YEAR,MONTH,DAY)		- returns the current date
debug				- will cause the tokens generated by the 
				  scanner to be displayed if there is a error 
				  in parsing
dir(Path,Filemask,Filename)	- call directory and returns selected filename
display(TERM*)			- outputs functors in prefix notation
edit(file)			- edit file, reconsult file
edit(pred/arity)		- edit selected predicate
edit_file(FILE)			- edits the file specified with an ASCII 
				  editor
edit				- save all clauses, edit, reconsult
eof				- tests for end of seeing file
existwindow(WindowNo)		- tests the existance of the specified window
fail				- fail
file_str(FILENAME,STRING)	- loads/saves a string from/to specified file
frontchar(STRING,CHAR,REST)	- returns first character and rest of the string
frontstr(REAL,STRING,FRONT,REST)- returns first string specified by the REAL
fronttoken(STRING,TOKEN,REST)	- returns the first token from the string
functor(TERM,FUNCTOR,ARITY)	- return functor and arity of term or build 
				  new
getbacktrack(BTOP)		- gets backtrack point for dynamic cut
GOAL , GOAL			- and
GOAL ; GOAL			- or
help				- help information
integer(TERM)			- is the term an integer
INTEGER is EXPRESSION		- evaluation of expressions
list(pred)			- list all clauses for pred
list(pred/arity)		- list selected arity
list				- list all clauses
makewindow(WinNo,ScrAtt,FAtt,FString,Row,Col,Height,Width)
				- makes a window according to the parameters
nl				- outputs a newline
nonvar(TERM)			- is the term bound
not(GOAL)			- negation
notrace				- turn off tracing
op(PRIORITY,ASSOC,OP)		- returns operators, or change operator
random(REAL)			- returns a randomly generated real number 
				  where 0>=REAL<1.
randominit(INTEGER)		- reinitializes random number generator with
				  a seed integer (default is 1)
read(TERM)			- read a term
readchar(CHAR)			- read a character
readln(LINE)			- read a line into a string
real(TERM)			- is the term for a real
reconsult(FILENAME)		- reconsult a file
removewindow			- removes current window
repeat				- succeeds forever
repeat(GOAL)			- succeeds until the goal fails
resizewindow			- resizes current window
retract(TERM)			- retract a term
save(FILENAME)			- save a file
scr_char(ROW,COL,CHAR)		- print a character on a selected position
searchstring(STRING,SEARCHSTRING,LOCATION)	- locates search string in 
	    			  the string and returns it's location
see(FILENAME)			- redirect input to this file
seeing(FILENAME)		- return the current input file
seen				- close the current input file
shiftwindow(No)			- shifts to the window specified
storage				- writes memory diagnostic information
str_atom(STRING,ATOM)		- conversion between a string and an atom
str_int(STRING,INT)		- conversion between a string and an integer
str_len(STRING,REAL)		- returns lenghth of the STRING
substring(STRING,START,LENGTH,SUBSTRING)	- returns a substring
system				- shells out to DOS
system(Command,VideoReset,Error)- shells out to DOS and executes Command
tell(FILENAME)			- redirect output to this file
telling(FILENAME)		- return the current output file
TERM =.. LIST			- univ; conversion between term and list
TERM == TERM			- testing for true equality
TERM =< TERM			- less than or equal
TERM = TERM			- unify two terms
TERM < TERM			- integer less than
TERM >= TERM			- greater than or equal
TERM >< TERM			- different evaluated values
TERM > TERM			- integer greater than
TERM \== TERM			- not true equality
TERM \= TERM			- test whether unify
time(HOUR,MIN,SEC,HUNDREDS)	- return the system time
told				- close the current output file
trace				- turn on tracing
true				- success
var(TERM)			- is the term a free variable
VAR				- call pred which VAR is bound to
window_str(String)		- reads/writes string from/to current window
write(TERM*)			- writes out a list of arguments


Math operators
=============================

+		- plus
-		- minus
*		- multiplication
/		- division
mod		- modulo
abs		- absolute value
cos		- cosine (units are in radians)
sin		- sine (units are in radians)
tan		- tangent (units are in radians)
arctan	- arctangent (units are in radians)
exp		- returns e raised to a power
ln		- natural logarithm
log		- logarithm
sqrt		- square root
round	- round
trunc	- truncate

Graphics System
	The graphics are based on a virtual screen.  The lower left hand 
corner is 0,0 and the upper right hand is 32000,32000.  It does not matter 
what graphic adapter is used, the screen coordinates are the same.  In 
addition to the normal lines, dots, ellipses etc., there are also turtle 
graphics commands and Bezier curves.  The graphics predicates are as 
follows:

angle(Angle)-(i)(o)	- sets or reads the turtles direction in degrees.

beep		- beeps the computer.

bezier(X1,Y1,CX1,CY1,CX2,CY2,X2,Y2)-(i,i,i,i,i,i,i,i)	- draws a Bezier 
curve with the end points X1,Y1 and X2,Y2 and with the control points 
CX1,CY1 and CX2,CY2.

bkcolor(Color)-(i)	sets the background color to Color.

circle(X,Y,Radius)-(i,i,i)	- draws a circle with a center at X,Y and 
with a radius of Radius.

closegraph	- closes the graphics system.

dot(X,Y)-(i,i)	- makes a dot at the location specified by X,Y.

dot	- makes a dot at the current location.

draw(GraphicsDriver,GraphMode)-(i,i)	- sets the computer to graphics 
mode using the driver specified in GraphicsDriver and the graphics mode 
specified by GraphMode.

draw(GraphMode)-(i)	- sets the computer to graphics mode specified by 
GraphMode.  The graphics driver is automatically called.

draw	- sets the computer to graphics mode.  The graphics driver and mode 
are automatically determined.

drawpoly(Pointlist)-(i,i,...i,i)	- draws a polygon with the point pairs 
specified.

elipse(X,Y,StAngle,EdAngle,Xradius,Yradius)-(i,i,i,i,i,i)	- draws an 
ellipse centered at X,Y starting at StAngle and ending at EdAngle with 
X and Y radii of Xradius and Yradius.

ellipse(X,Y,Xradius,Yradius)-(i,i,i,i)	- draws an ellipse centered at 
X,Y with X and Y radii of Xradius and Yradius.

fillstyle(Fillpattern,Fillcolor)-(i,i)(o,o)	- sets or returns the 
Fillpattern and Fillcolor.

floodfill(X,Y)-(i,i)	- floodfills an area with a pattern.

line(X1,Y1,X2,Y2)-(i,i,i,i)	- makes a line from X1,Y1 to X2,Y2.

lineto(X,Y)-(i,i)	- makes a line from the current location to X,Y.

move(Steps)-(i)	- moves the turtle a certain number of steps in the 
direction specified by the current angle.  Negative numbers moves the 
turtle backwards.

outtext(Text)-(i)	- writes Text to the screen at the current location 
and in the current font and color

outtext(X,Y,Text)-(i,i,i)	- writes Text to the screen at X,Y in the 
current font and color

pendown(Status)-(i)	- reports the marking status of the turtle.  The 
number 0 means the pen is up and 1 means the pen is down.

pendown	- causes the turtle to start making marks when it is moved.

penpos(X,Y)-(i,i)(o,o)	- sets or returns current pen location.

penup	- causes the turtle to stop making marks when it is moved.

rectangle(X1,Y1,X2,Y2)-(i,i,i,i)	- draws a rectangle with the upper 
left corner located at X1,Y1 and the lower right corner located at X2,Y2.

settextstyle(Font,Direction,Charsize)-(i,i,i)	- sets the current 
font, Direction, and Charsize.  The fonts are specified as: 0 = default 
bitmapped, 1 = triplex, 2 = small, 3 = sans serif, 4 = gothic.  Direction 
is specified as: 0 = horizontal (default) and 1 = vertical.  Charsize is 
an integer that specifies a magnification factor.

smooth(REAL)-(i)	- sets the smoothness of the bezier curves.
sound(Duration,Frequency)-(i,i)	- produces a sound with the specified 
Duration and Frequency.

text	- closes the graphics system and restores the text mode.

turn(Angle)-(i)	- turns the turtle the degrees specified in Angle.  
Positive angles turn the turtle left and negative angles turn the 
turtle right.


If you don't like our interpreter you are free to modify it and add
new standard predicates and features. If you have some nice
extensions we would like to see them in order to distribute a more
powerful interpreter.

Have Fun

Dan, Leo and Per

I modified this interpreter to add real arithmetic, windowing, commandline
interface, tail recursion optimization, dynamic cut, a repeat(Call) and a
graphics system predicate.  

Continue the fun

Brent
